package com.quanxiaoha.weblog.web.controller.record;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quanxiaoha.weblog.common.domain.entity.ScheduleHabit;
import com.quanxiaoha.weblog.common.domain.query.HabitCountQuery;
import com.quanxiaoha.weblog.common.domain.query.HabitQuery;
import com.quanxiaoha.weblog.common.service.IScheduleHabitService;
import com.quanxiaoha.weblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Roy
 * @since 2025-05-28
 */
@RestController
@Slf4j
@Api(tags = "习惯")
@RequestMapping("/todo")
public class ScheduleHabitController {

    @Autowired
    private IScheduleHabitService scheduleHabitService;

    @ApiOperation("获取习惯列表")
    @PostMapping("/habit/list")
    public Page<ScheduleHabit> getHabitList(@RequestBody HabitQuery habitQuery) {
        return scheduleHabitService.getHabitList(habitQuery);
    }

    @ApiOperation("获取习惯详情")
    @GetMapping("/habit/{id}")
    public ScheduleHabit getHabitDetail(@PathVariable Integer id) {
        return scheduleHabitService.getHabitDetail(id);
    }

    @ApiOperation("新增习惯")
    @PostMapping("/habit")
    public void createHabit(@RequestBody ScheduleHabit habit) {
        scheduleHabitService.createHabit(habit);
    }

    @ApiOperation("更新习惯")
    @PutMapping("/habit")
    public void updateHabit(@RequestBody ScheduleHabit habit) {
        scheduleHabitService.updateHabit(habit);
    }

    @ApiOperation("删除习惯")
    @DeleteMapping("/habit/{id}")
    public void deleteHabit(@PathVariable Integer id) {
        scheduleHabitService.deleteHabit(id);
    }

    @ApiOperation("更新完成数量")
    @PostMapping("/habit/count")
    public Response updateCompletedCount(@RequestBody HabitCountQuery query) {
        String reward = scheduleHabitService.updateCompletedCount(query);
        return Response.success(reward);
    }
}
